package com.yijiaw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yijiaw.domain.Us;
import com.yijiaw.service.UsService;

@Controller
@RequestMapping("/admin/contact")
public class ContactController {

	@Autowired
	UsService usService;
	
	@RequestMapping(method = RequestMethod.GET)
	public String contact(Model model) {
		List<Us> list = usService.findAllUss(0, 1);
		if (list != null && list.size() > 0) {
			Us us = list.get(0);
			model.addAttribute("us", us);
		}
		
		return "admin/contact"; 
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public String contact(@ModelAttribute Us us) {
		usService.saveUs(us);
		return "redirect:contact";
	}
	
}
